/* Copyright (C) 2021 Rain */

/* This file is part of XNIX. */

/* 
  XNIX is free software: you can redistribute it and/or modify 
  it under the terms of the GNU General Public License as published by 
  the Free Software Foundation, either version 3 of the License, or 
  (at your option) and later version. 
*/

/*
  XNIX is distributed in the hope that it will be useful, 
  but WITHOUT ANY WARRANTY; without even the implied warranty of 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  GNU General Public License for more details. 
*/

/*
  You should have received a copy of the GNU General Public License 
   along with XNIX. If not, see <https://www.gnu.org/licenses/>.  
*/



#ifndef _TSS_H
#define _TSS_H


/* init/head.S */
extern __uint64_t *gdt_table[];


struct tss_entry {
	__uint64_t low;
	__uint64_t high;
};



extern void *stack_start;


struct tss {
	__uint32_t rsvd0;
	__uint64_t rsp0;
	__uint64_t rsp1;
	__uint64_t rsp2;
	
	__uint64_t rsvd1;

	__uint64_t ist1, ist2, ist3, ist4;
	__uint64_t ist5, ist6, ist7;

	__uint64_t rsvd2;

	__uint16_t rsvd3;

	__uint16_t iomap_base;
} __attribute__ ((packed));


#define INIT_TSS {	\
	.rsvd0 = 0, 	\
	.rsp0 = 0,	\
	.rsp1 = 0,	\
	.rsp2 = 0,	\
	.rsvd1 = 0, 	\
	.ist1 = 0, 	\
	.ist2 = 0, 	\
	.ist3 = 0,	\
	.ist4 = 0, 	\
	.ist5 = 0, 	\
	.ist6 = 0, 	\
	.ist7 = 0, 	\
	.rsvd2 = 0, 	\
	.rsvd3 = 0,	\
	.iomap_base = 0	\
}


struct tss init_tss = INIT_TSS;


#endif
